<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<script src="${ctx}/jslib/jquery-1.8.3.js" type="text/javascript" charset="utf-8"></script>
<script src="${ctx}/jslib/layer/layer.js" type="text/javascript" charset="utf-8"></script>
<script src="${ctx}/jslib/SMValidator.min.js" type="text/javascript" charset="utf-8"></script>
<script src="${ctx }/jslib/jquery.form.js" type="text/javascript"></script>
<script type="text/javascript">

	$(function() {
        var ajaxFormOption = {
            type: "post",  //提交方式
            dataType: "json", //数据类型
            url: "${ctx}/user/editUserPwd", //请求url
            success: function (data) { //提交成功的回调函数
                if(data.success){
                    var index = layer.alert('密码修改成功！',{skin:'layui-layer-lan',title: ['系统提示', 'background-color:#00B2EE; color:#fff;'],closeBtn: 0}, function(index){
                        $("#editUserPwdForm")[0].reset();
                        layer.closeAll();
                    });
                }else{
                    var index = layer.alert(data.msg,{skin:'layui-layer-lan',title: ['系统提示', 'background-color:#00B2EE; color:#fff;'],closeBtn: 0}, function(index){
                        layer.close(index);
                    });
                }
            },
            error:function(){
                $("#user_submit").attr("disabled",false);
                layer.alert("网络连接有误，请稍后再试！");
            }
        };
        //不需要submit按钮，可以是任何元素的click事件
        $("#user_submit").click(function () {
            var result = SMValidator.validate('#editUserPwdForm');
           if(result){
               $("#editUserPwdForm").ajaxSubmit(ajaxFormOption);
           }
        });
	});

</script>
<div class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'center',border:false" title="" style="overflow: hidden;">
		<c:if test="${sessionInfo.name == null}">
			<div>登录已超时，请重新登录.</div>
			<script type="text/javascript" charset="utf-8">
				try {
					window.location.href='${ctx}/admin/index';
				} catch (e) {
				}
			</script>
		</c:if>
		<c:if test="${sessionInfo.name != null}">
			<form id="editUserPwdForm" method="post">
				<table cellpadding="10px">
					<tr>
						<th>登录名</th>
						<td style="height: 23px" >${sessionInfo.name}</td>
					</tr>
					<tr>
						<th>原密码</th>
						<td><input name="oldPwd" type="password" style="height: 23px" data-rule="required(请输入内容)|length(5,17)"></td>
					</tr>
					<tr>
						<th>新密码</th>
						<td><input name="pwd" id="pwd" type="password" style="height: 23px" data-rule="required(请输入内容)|length(5,17)"></td>
					</tr>
					<tr>
						<th>重复密码</th>
						<td><input name="rePwd" type="password" style="height: 23px" data-rule="required(请输入内容)|equal(#pwd)"></td>
					</tr>
                    <tr>
                        <td colspan="2" align="center"><input type="button" id="user_submit" class="query" value="提交"></td>
                    </tr>
				</table>
			</form>
            <script>
                SMValidator.setLang({
                    number: '请输入数字',
                    email: '请输入正确的邮箱格式',
                    range_equal: '值必须等于{0}',
                    range_scope: '值必须大于{0}且小于{1}',
                    range_greater: '值必须大于{0}',
                    range_less: '值必须小于{0}',
                    renge_no_number: '值必须是数字',
                    error_param: '参数错误',
                    length_equal: '长度必须为{0}',
                    length_scope: '长度必须大于{0}且小于{1}',
                    length_greater: '长度必须大于{0}',
                    length_less: '长度必须小于{0}',
                    password: '两次输入密码不一致'
                });

            </script>
		</c:if>
	</div>
</div>